//Write by oshogbo//vx
//23.07.2011
//http://code.google.com/p/streamobs

class JustinTV extends Stats implements ChannelType
{
  private String name;
  private boolean live = false;
  private static final String addres = "http://www.justin.tv/";
  private static final String hostName = "api.justin.tv";
  private static final String headerStart = "GET /api/stream/list.json?channel=";
  private static final String headerEnd = " HTTP/1.1\r\nHost: api.justin.tv\r\nUser-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; pl; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n";
  private String header;

  public JustinTV(String name)
  {
    this.name = name;
    header = headerStart + name + headerEnd;
  }

  public String getName()
  {
    return name;
  }

  public String getAddres()
  {
    return addres + name; 
  }

  public boolean isLive()
  {
    return live;
  }

  public void checkStatus()
  {
    String answer = refresh(hostName, header);

    if(answer != null && answer.toLowerCase().indexOf("content-length: 2v") == -1)
      live = true;
    else
      live = false;
  }
}
